package com.fcscs.ecms.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.fcscs.core.dao.ConnectionManager;
import com.fcscs.core.domain.BaseEntity.DBLoc;
import com.fcscs.ecms.dao.ECMSEntertainmentElmtsDao;
import com.fcscs.ecms.domain.MdlEntertainmentElmts;

/**
 * @author pvttinh
 * 
 */

@SuppressWarnings("unchecked")
@Repository("entertainmentElmtsDao")
public class ECMSEntertainmentElmtsDaoHibernate implements ECMSEntertainmentElmtsDao {
	
	@Autowired
	private ConnectionManager connMgr;
	//
	private static final String find_by_element_key = 
			"FROM MdlEntertainmentElmts mee "
		  + "WHERE mee.moduleId = :moduleId "
		  + "AND mee.proprietaryId = :proprietaryId ";
	
	@Override
	public List<MdlEntertainmentElmts> find(int moduleId, int proprietaryId) throws Exception {
		// TODO Auto-generated method stub
		List<MdlEntertainmentElmts> list = null;
		try{
			Query query = this.connMgr.getCurrentSession(DBLoc.GUEST).createQuery(
					ECMSEntertainmentElmtsDaoHibernate.find_by_element_key);
			query.setInteger("moduleId", moduleId);
			query.setInteger("proprietaryId", proprietaryId);
			
			list = query.list();
			if(list.isEmpty()){
				throw new Exception("ENTERTAINMENT ELMTS NOT FOUND");
			}
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("EntertainmentElmts.DAO.find() - " + e.getMessage());
		}				
		
		return list;
	}
}
